package com.example.shop_front_api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.shop_front_api.constant.ShopConstant;
import com.example.shop_front_api.entity.Product;
import com.example.shop_front_api.mapper.ProductMapper;
import com.example.shop_front_api.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public Product getProductById(Integer id) {
        return productMapper.selectById(id);
    }

    @Override
    public List<Product> getOnShelfProductsOrderBySales() {
        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", ShopConstant.PRODUCT_STATUS_ON)
                .orderByDesc("sales");
        return productMapper.selectList(queryWrapper);
    }

    @Override
    public int updateProductStock(Integer productId, Integer quantity) {
        return productMapper.updateStock(productId, quantity);
    }

    @Override
    public int updateProductLockStock(Integer productId, Integer lockStock) {
        return productMapper.updateLockStock(productId, lockStock);
    }
}